﻿using System.Text;
using Newtonsoft.Json;

namespace DataVisit.Handler
{
    public class JsonResponse : IJsonResponse
    {
        private bool _hasError = false;
        private StringBuilder _msg = new StringBuilder();
        private object _reObject;

        public bool HasError
        {
            set { _hasError = value; }
            get
            {
                return _hasError;
            }
        }

        public object ResponseObject
        {
            set
            {
            	_reObject = value;
            }
            get
            {
                return _reObject;
            }
        }

        public string Msg
        {
            get
            {
               return _msg.ToString();
            }
        }

        public void AddMsg(string msg)
        {
            _msg.Append(msg);
        }

        public void AddMsg(string msg, bool hasError)
        {
            HasError = hasError;
            AddMsg(msg);
        }

        public void ClearMsg()
        {
            _msg = new StringBuilder();
        }

        public string GetResponseString()
        {
           return JavaScriptConvert.SerializeObject(this);
        }
    }
}
